<?php
    
    
    include_once "include/constants.php";
	
    if (!defined('IS_AJAX')) {
        define('IS_AJAX', isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
    }


    try {
        $conn = new PDO('mysql:host='.DB_SERVER.';dbname='.DB_NAME, DB_USER, DB_PASS);
        $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
       
         
        $stmt = $conn->prepare('select * from movies;');
		$stmt->execute();
        
        $taste_data = array();
        while ($taste_row = $stmt->fetch()) {
            $taste_data[] = $taste_row;
        }
        
        $lala = json_encode($taste_data);
        echo "<script>lala=$lala;</script>";
        
    } catch(PDOException $e) {
        echo 'ERROR: ' . $e->getMessage();
    }
    
?>

<div id="bla">

</div>

<script>
    var bla = document.getElementById('bla'), str = "",
        tbls = ['movies','user_ratings','genres','locations','movielinks','movienights','movies2actors','movies2directors','movies2producers','movies2writers','plots','quotes','ratings','releasedates','runningtimes','trivia'];
    for (i in lala) {
        if (lala[i].title == null) {
            str += lala[i].movieid + ',';
        }
    }
    for (tbl in tbls) {
        bla.innerHTML += '<p>select * from '+tbls[tbl]+' where movieid in ('+str.slice(0, -1)+')</p>';
    }

</script>